/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/05/26
* File: enn_gl_texture_obj.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#pragma once

#include "enn_gl_interface.h"

namespace enn
{
class Image;
class TextureObj : public Noncopyable, public AllocatedObject
{
private:
	TextureObj();
	~TextureObj();
public:
	enum
	{
		TEXTURE_2D,
		TEXTURE_CUBE
	};

	struct TexDesc
	{
		int width_;
		int height_;
		GLint internal_format_;
		GLenum external_format_;
		int min_filter_;
		int mag_filter_;
		int wrap_s_;
		int wrap_t_;
		GLenum type_;
		uint32 texture_type_;
		bool is_mipmap_;
	};

	static TextureObj* createInstance();

	void release();

	void   createTexture();
	void   destroyTexture();

	void createTexture2D(const TexDesc& tex_desc, const void* data);
	void createTextureCube(const TexDesc& tex_desc, const void* data[6]);

	void updateTexture(const void* data);
	void updateCubeTexture(int face, const void* data);

protected:
	/** 2d texture */
	void   buildTexture(const void* data);

	/** 2d mipmap texture. */
	void   buildMipMapTexture(const void* data);

	/** cube texture */
	void buildCubeTexture(const void* data[6]);

public:
	bool load(Image* image);
	bool load_cube(int face, Image* image);

	bool save(Image* image);
	bool save_cube(int face, Image* image);
public:
	GLuint getHandle() const { return handle_; }
	const TexDesc& getTexDesc() const { return tex_desc_; }
protected:
	TexDesc tex_desc_;
	GLuint handle_;
};


}

